<template>
    <div>
      <el-container style="height: 100%; border: 1px solid #eee">
<!--        边框导航栏-->
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<!--          默认开启从1到1的导航栏-->
          <el-menu :default-openeds="['1', '1']">
            <el-menu-item index="1-1" >
              <router-link to="/admin/user">
              用户管理
              </router-link>
            </el-menu-item>
            <el-menu-item index="1-1" >
              <router-link to="/admin/artical">
                文章管理
              </router-link>
            </el-menu-item>
            <el-menu-item index="1-1" >
              <router-link to="/admin/channel">
               频道管理
              </router-link>
            </el-menu-item>

            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-medal-1"></i>
                <span>vip会员</span>
              </template>

            <el-menu-item index="1-1" >
              <router-link to="/admin/vip/manage">
                vip管理
              </router-link>
            </el-menu-item>
            <el-menu-item index="1-1" v-if="vipLevelFlag">
              <router-link to="/admin/vip/level">
                vip级别
              </router-link>
            </el-menu-item>
            <el-menu-item index="1-1"  v-if="vipVoucherFlag">
              <router-link to="/admin/vip/voucher">
                vip卷码
              </router-link>
            </el-menu-item>

            </el-submenu>

<!--            定义子菜单-->

          </el-menu>
        </el-aside>
<!--        内容容器-->
        <el-container>
<!--          头部菜单-->
          <el-header style="text-align: right; font-size: 12px">



              <router-link to="/">首页</router-link>

            <el-dropdown>
              <span>{{userInfo.id}}</span>
              <i class="el-icon-setting" style="margin-right: 15px"></i>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item ><button @click="loginOut">退出</button></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

          </el-header>
<!--          内容容器-->
          <el-main class="content">
            <router-view></router-view>

          </el-main>
        </el-container>
      </el-container>

    </div>
</template>


<script>
  import {ResultStatus} from "../constant/ResultStatus";
  import {UserPower} from "../constant/UserPower";

  export default {
    data() {

      return {
        userInfo:this.$store.getters.getUserInfo,
        vipLevelFlag:false,//
        vipVoucherFlag:false,

      }
    },
    methods:{
      /**
       * 退出
       * 清除cookie
       * 清除sesstion Strong
       */
      loginOut : async function(){

        // 为给定 ID 的 user 创建请求
        await this.$axios.get('/user/logout')
          .then(function (response) {
          })
          .catch(function (error) {
            console.log(error);
          });
        document.cookie=ResultStatus.SSO_TOKEN_KEY+"=";
        this.$store.dispatch("setUserInfo", null);
        this.$router.push({name:'home'})
        location.reload();//重新加载当前页面

      },
      /**
       *
       */
      initFlag(){
        if(this.userInfo.power != UserPower.Users){
          this.vipLevelFlag = true;
          this.vipVoucherFlag = true;
        }
      }

    },

    components:{

    },
    mounted(){
      this.initFlag();
    }

  };
</script>

<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }

  .el-aside {
    color: #333;
  }
  .content{
    text-align: left;
  }
  A{
    text-decoration: none;
    color:#333;
  }
</style>

